import React from 'react'
import '../../assets/css/profile/setpwd.less'
import connect from "react-redux/es/connect/connect";
import {Switch, Toast} from "antd-mobile";
class SetPwdComponent extends React.Component {
    constructor(props){
        super(props)
        this.state={
            uid:props.state.userInfo.uid,
            pwd:'',
            checked:false
        }
    }

    goBack(){
        this.props.history.goBack()
    }
    setPwd(){
        if(this.state.pwd.length<6){
            return
        }
        console.log(this.state);
        const parmas = new URLSearchParams()
        parmas.append('uid',this.state.uid)
        parmas.append('password',this.state.pwd)
        fetch('http://vueshop.glbuys.com/api/user/myinfo/modpwd?token=1ec949a15fb709370f',{
            method:'POST',
            body:parmas
        }).then((res)=>res.json())
            .then((res)=>{
                console.log(res);
                if(res.code===200){
                    Toast.success('修改成功', 1);
                    this.goBack()
                }
            })
    }
    render() {
        return(
            <div id='setpwd'>
                <div className='header'>
                    <div onClick={this.goBack.bind(this)}>
                        <img src="/images/user/my/返回.png" alt=""/>
                    </div>
                    <div>修改密码</div>
                    <div></div>
                </div>
                <div>
                    <div className='pwdBtn'>
                        <input type={this.state.checked?'text':'password'} placeholder='请输入不小于6位的密码'
                            onChange={(e)=>{
                                this.setState({
                                    pwd:e.target.value
                                })
                            }}
                        />
                        <Switch
                            checked={this.state.checked}
                            onChange={() => {
                                this.setState({
                                    checked: !this.state.checked,
                                });
                            }}
                        />
                    </div>
                    <div className='submit' onClick={this.setPwd.bind(this)}>提交</div>
                </div>

            </div>
        )
    }
}
export default  connect((state)=>{
    return{
        state
    }
})(SetPwdComponent)